package com.example.controller;

import com.example.common.Result;
import com.example.entity.PlaylistItem;
import com.example.entity.Sing;
import com.example.entity.Singer;
import com.example.service.PlaylistItemService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import java.util.List;

/**
 * 前端操作接口
 **/
@RestController
@RequestMapping("/playlistItem")
public class PlaylistItemController {

    @Resource
    private PlaylistItemService playlistItemService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody PlaylistItem playlistItem) {
        playlistItemService.add(playlistItem);
        return Result.success();
    }

    /**
     * 移除歌曲
     */
    @PostMapping("/deleteSong")
    public Result deleteSong(@RequestBody PlaylistItem playlistItem) {
        playlistItemService.deleteSong(playlistItem);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        playlistItemService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        playlistItemService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody PlaylistItem playlistItem) {
        playlistItemService.updateById(playlistItem);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        PlaylistItem playlistItem = playlistItemService.selectById(id);
        return Result.success(playlistItem);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(PlaylistItem playlistItem) {
        List<PlaylistItem> list = playlistItemService.selectAll(playlistItem);
        return Result.success(list);
    }

    /**
     * 查询所有歌曲
     */
    @GetMapping("/selectAllSongs")
    public Result selectAllSongs(PlaylistItem playlistItem) {
        List<Sing> list = playlistItemService.selectAllSongs(playlistItem);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(PlaylistItem playlistItem,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<PlaylistItem> page = playlistItemService.selectPage(playlistItem, pageNum, pageSize);
        return Result.success(page);
    }

}